(DEFUN c:flatblks ()
  (IF (EQ (GETVAR "TILEMODE") 1)
    (SETQ blklist (SSGET '((0 . "INSERT")(67 . 0)));blocks in model space
          blkspace "Model Space"
    )
    (SETQ blklist (SSGET '((0 . "INSERT")(67 . 1)));blocks in paper space
          blkspace "Paper Space"
    )
  )
  (SETQ flatblkcnt (SSLENGTH blklist))
  (PRINC "\n")
  (PRINC (ITOA flatblkcnt))
  (PRINC (STRCAT " " blkspace " blocks selected for flattening."))
  (PRINC)
  (SETQ blkcnt 0)
  (SETQ flatblk-ss (SSADD))
  (WHILE (< blkcnt (SSLENGTH blklist))
    (SETQ thisblkename (SSNAME blklist blkcnt)
          thisblockent (ENTGET thisblkename)
          thisblkname (CDR (ASSOC 2 thisblockent))
          thisblkdef (TBLSEARCH "BLOCK" thisblkname)
    )
    (IF (OR
          (EQ (BOOLE 1 1 (CDR (ASSOC 70 thisblkdef))) 1)
          (EQ (BOOLE 1 4 (CDR (ASSOC 70 thisblkdef))) 4)
          (EQ (BOOLE 1 8 (CDR (ASSOC 70 thisblkdef))) 8)
          (EQ (BOOLE 1 16 (CDR (ASSOC 70 thisblkdef))) 16)
          (EQ (BOOLE 1 32 (CDR (ASSOC 70 thisblkdef))) 32)
          (EQ (BOOLE 1 64 (CDR (ASSOC 70 thisblkdef))) 64)
        )
      NIL
      (SETQ flatblk-ss (SSADD thisblkename flatblk-ss))
    )
    (SETQ blkcnt (1+ blkcnt))
  )
  (IF (AND
        flatblk-ss
        (> (SSLENGTH flatblk-ss) 0)
      )
    (PROGN
      (SETQ blkcnt 0)
      (WHILE (< blkcnt (SSLENGTH flatblk-ss))
        (SETQ thisblkent (ENTGET (SSNAME flatblk-ss blkcnt)))
        (SETQ thisblkent
               (SUBST
                 (CONS 10
                       (LIST
                         (CADR (ASSOC 10 thisblkent))
                         (CADDR (ASSOC 10 thisblkent))
                         0.0
                       )
                 )
                 (ASSOC 10 thisblkent)
                 thisblkent
               )
        )
        (ENTMOD thisblkent)
        (SETQ blkcnt (1+ blkcnt))
      )
      (SETQ flatblkcnt (SSLENGTH flatblk-ss))
      (PRINC "\n")
      (PRINC (ITOA flatblkcnt))
      (PRINC (STRCAT " " blkspace " blocks flattened. Anonymous and external references were excluded."))
      (PRINC)
    )
  )
  (PRINC)
)